package repository

import (
	"context"
	"time"

	"github.com/google/uuid"
	"techoiceness.com/aiagent/llm-gateway/internal/entity"
)

// LLMMessageRepository LLM消息存储接口 (仅处理LLM消息实体)
type LLMMessageRepository interface {
	// 消息查询
	GetMessagesByConversation(ctx context.Context, conversationID uuid.UUID) ([]entity.LLMMessage, error)
	GetMessagesPaginated(ctx context.Context, conversationID uuid.UUID, limit, offset int) ([]entity.LLMMessage, int64, error)
	GetLatestMessages(ctx context.Context, conversationID uuid.UUID, limit int) ([]entity.LLMMessage, error)
	GetMessageByID(ctx context.Context, messageID uint) (*entity.LLMMessage, error)

	// 消息保存
	SaveMessage(ctx context.Context, message *entity.LLMMessage) error
	SaveMessages(ctx context.Context, messages []*entity.LLMMessage) error

	// 消息管理
	UpdateMessage(ctx context.Context, messageID uint, content string) error
	DeleteMessage(ctx context.Context, messageID uint) error
	DeleteMessagesByConversation(ctx context.Context, conversationID uuid.UUID) error

	// 消息统计
	GetMessageCount(ctx context.Context, conversationID uuid.UUID) (int64, error)
	GetTotalMessageCount(ctx context.Context) (int64, error)

	// 消息清理
	CleanupOldMessages(ctx context.Context, before time.Time) (int64, error)

	// 客户端消息关联查询
	// 根据客户端消息ID获取对应的所有LLM消息（按序号排序）
	GetMessagesByClientMessageID(ctx context.Context, clientMessageID uuid.UUID) ([]entity.LLMMessage, error)

	// 获取客户端消息对应的下一个消息序号
	GetNextMessageSequence(ctx context.Context, clientMessageID uuid.UUID) (int, error)
}
